//
//  DataBaseManager.m
//  Unicorn
//
//  Created by xalo on 16/5/5.
//  Copyright © 2016年 bhj_jun. All rights reserved.
//

#import "DataBaseManager.h"

@implementation DataBaseManager

+(DataBaseManager *)shareManager{

    static DataBaseManager *handle=nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        handle=[[DataBaseManager alloc]init];
    });
    return handle;
}


-(instancetype)init{

    self=[super init];
    if (self) {
        
        self.context=[[NSManagedObjectContext alloc]initWithConcurrencyType:NSPrivateQueueConcurrencyType];   //私有线程
        // 关联表模型
        NSManagedObjectModel *model=[[NSManagedObjectModel alloc]initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"LawyerData" withExtension:@"momd"]];
        //
        NSPersistentStoreCoordinator *coordinator=[[NSPersistentStoreCoordinator alloc]initWithManagedObjectModel:model];
        // 沙盒路径
        NSString *path=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
        // 文件路径
        NSString *fileName=[path stringByAppendingPathComponent:@"LawyerData.sqlite"];
//        NSLog(@"filename-------%@",fileName);
        [coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[NSURL fileURLWithPath:fileName] options:nil error:nil];
        self.context.persistentStoreCoordinator=coordinator;
    }
    return self;
}


// 增
-(void)insertData:(LawyerModel *)model{







}





// 删
// 查






@end
